package com.hxkj.config;


import com.integral.mall.file.po.SpringContextHolder;
import com.integral.mall.file.storage.StorageFactory;
import com.integral.mall.file.storage.sftp.SFTPStorage;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * sftp文件上传配置
 * <p>
 * Created by chenwei on 2017/12/04.
 */
@Configuration
public class SftpConfig {

		/**
		 * 存储工厂
		 *
		 * @return
		 */
		@Bean("storageFactory")
		@ConfigurationProperties(prefix = "storage.sftp")
		public StorageFactory storageFactory() {
				return new StorageFactory();
		}


		@Bean("springContextHolder")
		public SpringContextHolder springContextHolder() {
				SpringContextHolder springContextHolder = new SpringContextHolder();
				return springContextHolder;
		}


		@Bean(value = "storage", initMethod = "init", destroyMethod = "destroy")
		public SFTPStorage sftpStorage(StorageFactory storageFactory) throws Exception {
				SFTPStorage sftpStorage = (SFTPStorage) storageFactory.getStorage();
				return sftpStorage;
		}


}
